package org.stream;

import org.entity.Employee;
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.List;
import java.util.SortedSet;
import java.util.TreeSet;
import java.util.stream.Collectors;

/**
 * @Description
 * @Author wjj
 * @Date 2023/4/17 23:01
 */
public class Collector {
//    <R> R collect(Supplier<R> supplier, BiConsumer<R,? super T> accumulator, BiConsumer<R,R> combiner)
//    <R,A> R collect(Collector<?  super T,A,R> collector)
    @Test
    public void collectionTest(){
        ArrayList<String> names = Employee.persons()
                .stream()
                .map(Employee::getName)
                .collect(ArrayList::new, ArrayList::add, ArrayList::addAll);
        System.out.println(names);
    }

    @Test
    public void collectionTest2(){
        List<String> names = Employee.persons()
                .stream()
                .map(Employee::getName)
                .collect(java.util.stream.Collectors.toList());
        System.out.println(names);
    }

    /*排序*/
    @Test
    public void collectionTest3(){
        SortedSet<String> uniqueSortedNames =   Employee.persons()
                .stream()
                .map(Employee::getName)
                .collect(Collectors.toCollection(TreeSet::new));
        System.out.println(uniqueSortedNames);
    }
}
